import java.util.Arrays;
import java.util.Scanner;

public class 数组的删除 {
	public static void main(String[] args) {

		// 定义数组
		int[] arr = { 2, 4, 3, 6, 5, 7 };
		System.out.println(Arrays.toString(arr));
		Scanner sc = new Scanner(System.in);

		System.out.println("请输入你要删除的数字");
		int num = sc.nextInt();
		//
		int index = findIndex(arr, num);
		arr = del(arr, index);
		System.out.println(Arrays.toString(arr));
	}

	/**
	 * 
	 * @param arr
	 * @param index
	 * @return
	 */
	static int[] del(int[] arr, int index) {
		int[] newArr = new int[arr.length - 1];

		for (int i = 0; i < newArr.length; i++) {
			if (i < index) {
				newArr[i] = arr[i];
			} else {
				newArr[i] = arr[i + 1];
			}
		}
		return newArr;
	}

	/**
	 * 查找方法 元素存在返回元素所在的索引，元素不存在返回-1
	 * 
	 * @param arr
	 * @param num
	 * @return
	 */
	static int findIndex(int[] arr, int num) {
		for (int i = 0; i < arr.length; i++) {
			if (num == arr[i]) {
				return i;
			}
		}
		return -1;
	}

}
